<template>
  <div class="app-container">
	<div class="app-layout">
		<div class="pane" style="width: 100%;">
			<div class="head">
				<span>日志列表</span>
			</div>
			<div class="body">
				<div class="table-tool-bar" style="margin-bottom: 5px;">
					<div>
						
					</div>
					<div>
						<el-input
						  v-model="queryParams.keywords"
						  placeholder="输入日志内容进行搜索"
						  clearable
						  style="width: 250px;margin-right: 5px;"
						  @keyup.enter="handleQuery"
						/>
						
						<el-date-picker
						  v-model="queryParams.createTime"
						  :editable="false"
						  class="!w-[240px]"
						  type="daterange"
						  range-separator="~"
						  start-placeholder="开始时间"
						  end-placeholder="截止时间"
						  value-format="YYYY-MM-DD"
						  style="margin-right: 8px;"
						/>
						
						<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
						<el-button icon="refresh" @click="handleResetQuery">重置</el-button>
					</div>
				</div>
				<div>
					<el-table v-loading="loading" :data="pageData" highlight-current-row border height="calc(100vh - 260px)">
						<el-table-column label="操作时间" prop="createTime" width="180" />
						<el-table-column label="操作人" prop="operator" width="120" />
						<el-table-column label="日志模块" prop="module" width="100" />
						<el-table-column label="日志内容" prop="content" min-width="200" />
						<el-table-column label="IP 地址" prop="requestIp" width="150" />
						<el-table-column label="终端系统" prop="userAgent" width="200" show-overflow-tooltip />
						<el-table-column label="执行时间(ms)" prop="duration" width="150" />
					</el-table>
					<div style="display: flex;justify-content: flex-end;align-items: center">
						<pagination
						  v-model:total="total"
						  v-model:page="queryParams.cur"
						  v-model:limit="queryParams.limit"
						  @pagination="handleQuery"
						/>
					</div>
				</div>
			</div>
		</div>
	</div>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "Log",
  inheritAttrs: false,
});

import LogAPI, { LogPageVO, LogPageQuery } from "@/api/system/log";

const loading = ref(false);
const total = ref(0);

const queryParams = reactive<LogPageQuery>({
  cur: 1,
  limit: 10,
  keywords: "",
  createTime: ["", ""],
});

// 日志表格数据
const pageData = ref<LogPageVO[]>();

/** 查询 */
function handleQuery() {
  loading.value = true;
  LogAPI.getPage(queryParams)
    .then((data) => {
      pageData.value = data.list;
      total.value = data.totalRow;
    })
    .finally(() => {
      loading.value = false;
    });
}
/** 重置查询 */
function handleResetQuery() {
  queryParams.cur = 1;
  queryParams.createTime = undefined;
  queryParams.keywords="";
  handleQuery();
}

onMounted(() => {
  handleQuery();
});
</script>
